﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;
using WebApplication1.Service.IService;

namespace WebApplication1.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly IUserService _userService;
        public ValuesController(IUserService userService)
        {
            _userService = userService;
        }

        [HttpGet]
        public async Task<object> Get()
        {


            return await _userService.GetUserAllAsync();
        }


        [HttpPut]
        public async Task<object> EditUser(userinfo userinfo)
        {


            if (await _userService.UpdateAsync(userinfo) > 0)
            {
                return new { code = 200, msg = "成功！" };
            }
            return new { code = 500, msg = "失败！" };
        }


        [HttpPost]
        public async Task<object> AddUser(userinfo userinfo)
        {


            if (await _userService.AddUserAsync(userinfo) > 0)
            {
                return new { code = 200, msg = "成功！" };
            }
            return new { code = 500, msg = "失败！" };
        }


        [HttpPost]
        public async Task<object> DeleteUser(int userid)
        {



            if (await _userService.RemoveAsync(userid) > 0)
            {
                return new { code = 200, msg = "成功！" };
            }
            return new { code = 500, msg = "失败！" };
        }

    }
}
